package Top;

import java.util.HashMap;

public class offer3 {

    public int lengthOfLongestSubstring(String s) {
        HashMap<Character, Integer> map = new HashMap<>();
        int left = 0;
        int maxlen = 0;
        int length = s.length();
        for (int i = 0; i < length; i++) {
            if (map.containsKey(s.charAt(i))) {
                left = Math.max(left, map.get(s.charAt(i)) + 1);
            }
            map.put(s.charAt(i),i);
            maxlen=Math.max(maxlen,i-left+1);
        }
        return maxlen;
    }

    public static void main(String[] args) {
        offer3 demo=new offer3();
        System.out.println(demo.lengthOfLongestSubstring("abcabc"));
    }
}
